package io.gitee.mojingjiao.day05;

import org.junit.Assert;
import org.junit.Test;

import java.security.Key;
import java.util.HashMap;
import java.util.Map;
public class TestNum {
    @Test
    public void test(){

      String s="Stack Overflow requires external JavaScript from " +
            "overflow another or domain, which is blocked or failed to or load.";
    Map<String,Integer>map=countEach(s);
        System.out.println(map.get("or"));
        Assert.assertEquals(new Integer(1),map.get("stack"));
        Assert.assertEquals(new Integer(3),map.get("or"));
        Assert.assertEquals(new Integer(2),map.get("overflow"));
    }

   public Map<String,Integer>countEach(String s) {
       String[] strings = s.split("[,. ]");
       Map<String, Integer> map = new HashMap<>();
       for (String e : strings) {
           String lowcase = e.toLowerCase();
           if (map.containsKey(lowcase)) {
               map.put(lowcase, map.get(lowcase) + 1);
           } else {
               map.put(lowcase, 1);
           }
       }
       return map;
   }
}
